import json

import pymysql,requests,urllib3,datetime,re,asyncio,aiohttp,time,aiofiles
from lxml import etree
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

#爬虫

"""
1,同步操作 访问getCatalog ，拿到cid和名称
2，异步操作 方位getChapterContent 下载内容
"""
async def getpa(url):
     async with aiohttp.ClientSession() as session:
          async with session.get(url) as resp:
               await resp.text()

async def rang(times):
     tasks = []
     for i in range(times):
         d = asyncio.create_task(getpa('http://49.233.17.152:1607/jspro.php'))
         tasks.append(d)
     await asyncio.wait(tasks)

def getnum(url):
     res = requests.get(url).text
     num = eval(''.join(re.findall(r'【人数】(.*?)【人数】',res)))
     numC = 210000 - num
     return numC


if __name__ == '__main__':
     start = time.time()
     numC = getnum('http://49.233.17.152:1607/jspro.php')
     loop = asyncio.new_event_loop()
     asyncio.set_event_loop(loop)
     loop.run_until_complete(rang(numC))
     while numC != 0:
          loop.run_until_complete(rang(numC))
     end = time.time() - start
     print(end)

